const config = require('../../../config/config.local');
const amazonMws = require('amazon-mws')(config.AWSAccessKeyId, config.AWSSecretKey);
const isProduction = process.env.NODE_ENV === 'production';

const updateInboundShipment = {};
updateInboundShipment.generateOption = function(seller_id, mws_auth_token, shipmentId, inboundShipmentHeader, inboundShipmentItems){
  let baseOption = {
    'Version': '2010-10-01',
    'Action': 'UpdateInboundShipment',
    'SellerId': seller_id,
    'MWSAuthToken': mws_auth_token,
    'ShipmentId': shipmentId,
  };

  const option = Object.assign(baseOption,
    jsonflatten.flatten(inboundShipmentHeader, null, baseIndex=1),
    jsonflatten.flatten(inboundShipmentItems, null, baseIndex=1));
  return option;
};

updateInboundShipment._ = function(options) {
  if (!isProduction) {
    return amazonMws.fulfillmentInboundShipment.search(options);
  } else {
    console.error("bot not implemented!")
  }
};

updateInboundShipment.updateInboundShipment = function(seller_id, mws_auth_token, shipmentId, inboundShipmentHeader, inboundShipmentItems) {
  return this._(this.generateOption(seller_id, mws_auth_token, shipmentId, inboundShipmentHeader, inboundShipmentItems));
};

module.exports = updateInboundShipment;